import request from '@/utils/request';
import IS_MOCK, { BASE_URL } from '@/utils/url';

//获取设备列表
export async function getDetectorList(params) {
  const { pagination, formData, detectorData } = params;
  return IS_MOCK
    ? request(`/api/detector/getDetectorList`, {
      method: 'post',
      data: {
        size: '10',
        start: '1',
        ...params.detectorData,
        ...params.formData,
      },
    })
    : request(
      `${BASE_URL}/detector/getDetectorList?size=${pagination.size}&start=${pagination.start}`,
      {
        method: 'post',
        data: {
          ...formData,
          ...detectorData,
        },
      },
    );
}


export async function addNewDetector(params) {
  return IS_MOCK
    ? request('/api/detector/insert', {
      method: 'post',
    })
    : request(`${BASE_URL}/detector/insert`, {
      method: 'post',
      data: params,
    });
}

export async function updateDetector(params) {
  return IS_MOCK
    ? request('/api/detector/update', {
      method: 'post',
    })
    : request(`${BASE_URL}/detector/insert`, {
      method: 'post',
      data: params,
    });
}

export async function deleteDetector(params) {
  return IS_MOCK
    ? request('/api/detector/delete', {
      method: 'post',
    })
    : request(`${BASE_URL}/detector/delete?id=` + `${params.id}`, {
      method: 'get',
    });
}

export async function addDetectorPushUserById(params) {
  return IS_MOCK
    ? request('/api/detector/insertDetectorPushUserById', {
      method: 'post',
    })
    : request(`${BASE_URL}/alarm/insertDetectorPushUserById`, {
      method: 'post',
      data: params,
    });
}

//根据userId删除推送用户信息
export async function deleteDetectorUser(params) {
  return IS_MOCK
    ? request('/api/detector/deleteDetectorUser', {
      method: 'post',
    })
    : request(`${BASE_URL}/alarm/deleteDetectorUser`, {
      method: 'post',
      data: params,
    });
}

export async function getDetectorInfoById(params) {
  return IS_MOCK
    ? request('/api/detector/getDetectorInfoById', {
      method: 'post',
    })
    : request(`${BASE_URL}/detector/getDetectorInfoById`, {
      method: 'post',
      data: params,
    });
}


